package com.genia.toolbox.projects.sample_ws_trampo.war.plugin;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;

import com.genia.toolbox.basics.exception.technical.TechnicalException;
import com.genia.toolbox.spring.provider.plugin.impl.AbstractSimpleSpringProviderPlugin;
import com.genia.toolbox.web.servlet.CustomContextLoaderListener;

public class SampleWsTrampoWarSpringProviderPlugin extends AbstractSimpleSpringProviderPlugin{
	 /**
	   * the main config file.
	   */
	  private static final String MAIN_CONFIG_FILE_RESOURCE = "/com/genia/toolbox/projects/sample_ws_trampo/war/plugin/main-spring-config.xml";

	   /**
	   * the web service endpoints config file.
	   */
	  private static final String WS_ENDPOINTS_CONFIG_FILE_RESOURCE = "/com/genia/toolbox/projects/sample_ws_trampo/war/plugin/ws-endpoints-spring-config.xml";

	  /**
	   * Constructor
	   */
	  public SampleWsTrampoWarSpringProviderPlugin()
	  {
		  super(MAIN_CONFIG_FILE_RESOURCE);
	  }

	  /**
	   * Return a {@link Collection} of {@link InputStream} that contains Spring
	   * config files.
	   *
	   * @return a {@link Collection} of {@link InputStream} that contains Spring
	   *         config files
	   * @throws TechnicalException
	   *           when a configuration file does not exists
	   * @see com.genia.toolbox.spring.provider.plugin.SpringProviderPlugin#getConfigurations()
	   */

	  @Override
	  public Collection<InputStream> getConfigurations()
	      throws TechnicalException
	  {
	    Collection<InputStream> result = new ArrayList<InputStream>(super.getConfigurations());
	   if (CustomContextLoaderListener.isWebApplicationContextInitializing()) {
	     result.add(getClass().getResourceAsStream(WS_ENDPOINTS_CONFIG_FILE_RESOURCE));
	   }
	    return result;
	  }

}
